package ${thisPackage}.service;

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import ${thisPackage}.dao.*;
import ${thisPackage}.domain.*;


/**
 * auto generate by wencst
 * @author ${author}
 * @since ${.now}
 */
 
<#list columns as col>
	<#if col.primaryKey>
		<#assign  primaryKeyType=col.javaType/>
	<#break>
	</#if>
</#list>
@Service
public class ${javaBeanName}Service{
 
    @Autowired
    protected ${javaBeanName}Dao baseDao;
 
    public int save(${javaBeanName} bean) {
        try {
            baseDao.save(bean);
            return 1;
        }catch (Exception e) {
            return -1;
        }
    }
 
    public int update(${javaBeanName} bean) {
        try {
            baseDao.save(bean);
            return 1;
        }catch (Exception e) {
            return -1;
        }
    }
 
    public int delete(${primaryKeyType} id) {
        baseDao.deleteById(id);
        return 1;
    }
 
 
    public List<${javaBeanName}> listAll() {
        return baseDao.findAll();
    }

    public ${javaBeanName} detail(${primaryKeyType} id) {
    	Optional<${javaBeanName}> ot = baseDao.findById(id);
    	if (ot == null) {
    		return null;
    	}
        return ot.get();
    }

    public Page<${javaBeanName}> listByPage(Pageable pa) {
        return baseDao.findAll(pa);
    }
}